package com.hyg.module_health.view.activity.HourTwelveActivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.hyg.module_health.R;
import com.hyg.module_health.model.datamodel.ShiChenYangShengData;

import java.util.ArrayList;


public class HourTwelveAdapter extends RecyclerView.Adapter<HourTwelveAdapter.ViewHolder>{

    private Context context;
    private ArrayList<ShiChenYangShengData> dataList;
    private HourTwelveAdapter.OnItemClickLitener mOnItemClickLitener;

    public HourTwelveAdapter(Context activity, ArrayList<ShiChenYangShengData> dataList) {
        this.context = activity.getApplicationContext();
        this.dataList = dataList;
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);

        void onItemLongClick(View view, int position);
    }

    public void setOnItemClickLitener(HourTwelveAdapter.OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public HourTwelveAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hour_list,
                parent, false);
        HourTwelveAdapter.ViewHolder holder = new HourTwelveAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final HourTwelveAdapter.ViewHolder holder, int position) {
        HourTwelveAdapter.ViewHolder viewHolder = (HourTwelveAdapter.ViewHolder) holder;
        viewHolder.bindView(dataList.get(position), position);
    }

    @Override
    public int getItemCount() {
        if (dataList == null) {
            return 0;
        }
        return dataList.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView iv_shichen;
        private TextView tv_shichen;
        private TextView tv_suitable;
        private TextView tv_taboo;
        private TextView tv_qujian;
        private RecyclerView rv_shichen_msg;


        public ViewHolder(View itemView) {
            super(itemView);
            iv_shichen = (ImageView) itemView.findViewById(R.id.iv_shichen);
            tv_shichen = (TextView) itemView.findViewById(R.id.tv_shichen);
            tv_suitable = (TextView) itemView.findViewById(R.id.tv_suitable);
            tv_taboo = (TextView) itemView.findViewById(R.id.tv_taboo);
            tv_qujian = (TextView) itemView.findViewById(R.id.tv_qujian);
            rv_shichen_msg = (RecyclerView) itemView.findViewById(R.id.rv_shichen_msg);
        }

        public void bindView(ShiChenYangShengData data , int position){

            Glide.with(context)
                    .load(data.getShiChenImageID())
                    .into(iv_shichen);
            tv_shichen.setText(data.getShiChen_Name());
            tv_suitable.setText(data.getSuitable());
            tv_taboo.setText(data.getTaboo());
            tv_qujian.setText(data.getStartTime() +" - "+ data.getEndTime());
            //设置布局方式
            rv_shichen_msg.setLayoutManager(new LinearLayoutManager(context));
//            rv_shichen_msg.setHasFixedSize(true);//当我们确定Item的改变不会影响RecyclerView的宽高的时候可以设置setHasFixedSize(true)
            rv_shichen_msg.setNestedScrollingEnabled(false);
            rv_shichen_msg.setAdapter(new StringAdapter(data.getMessage()));
            rv_shichen_msg.setItemAnimator(new DefaultItemAnimator());


        }

    }
}
